/*
* @Description: router.js
* @Verson: v1.0
* @Author: xvyy
* @Date: 2024-11-29 09:27
*/
import {createRouter, createWebHashHistory} from 'vue-router'
import Home from "../components/Home.vue";
import Login from "../components/Login.vue";

let router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: Home,
            // component: () => import('@/views/index.vue')
        },
        {
            path: '/login',
            component: Login,
            // component: () => import('@/views/index.vue')
        }
    ]
})

router.beforeEach((to, from, next) => {
    let username = localStorage.getItem('username')
    if (username == null) {
        if (to.path == '/login') {
            next()
        } else {
            next('/login')
        }
    } else {
        next()
    }
})

export default router